package cz.muni.fi.pb138.bookinfo;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringEscapeUtils;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Review extends Activity {
	private String reviews = "";
	private TextView reviewsTV;
	
	/** Called when the activity is first created. 
	 * 	Shows the review of selected book in web browser.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.review);
		
		reviewsTV = (TextView) findViewById(R.id.reviews);
		
		Bundle data = getIntent().getBundleExtra("reviews");
		List<String> bookReviews = new ArrayList<String>();
		bookReviews.addAll(data.getStringArrayList("reviews"));
		if(bookReviews != null && bookReviews.size() > 0) {
			for(int i = 0; i < bookReviews.size(); i++) {
				if(i == 5) break;
				if(i < 4) {
					reviews += StringEscapeUtils.unescapeHtml4(bookReviews.get(i)) + "\n\n";
				} else {
					reviews += StringEscapeUtils.unescapeHtml4(bookReviews.get(i));
				}
			}
		}
		
		if(bookReviews == null || bookReviews.size() == 0) {
			reviewsTV.setText("NO REVIEWS FOUND!");
		} else {
			reviews = reviews.replace("<br>", "\n");
			reviewsTV.setText(reviews);
		}
	}
}
